package com.yixuan.yh.product.mapper;

import com.yixuan.yh.product.pojo.model.entity.ProductSku;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ProductSkuMapper {

    @Select("select sku_id from product_sku where product_id = #{productId}")
    List<Long> selectSkuIdByProductId(Long productId);

    @Select("select sku_id, price, stock from product_sku where product_id = #{productId}")
    List<ProductSku> selectByProductId(Long productId);

    void insertBatch(Long productId, List<Long> skuIdList);

    @Delete("delete from product_sku where product_id = #{productId}")
    void deleteByProductId(Long productId);

    void deleteBatch(List<Long> skuIdList);

    void update(List<ProductSku> productSkuList);

    @Select("select product_id from product_sku where sku_id = #{skuId}")
    Long selectProductIdBySkuId(Long skuId);

    List<ProductSku> selectPartOfCartItem(List<Long> skuIdList);

    @Select("select price from product_sku where sku_id = #{skuId}")
    ProductSku selectPriceBySkuId(Long skuId);

    @Select("select stock from product_sku where sku_id = #{skuId}")
    Integer selectStockBySkuId(Long skuId);

    @Update("update product_sku set stock = stock + #{quantity} where sku_id = #{skuId}")
    void updateStock(Long skuId, Integer quantity);
}
